<template>
  <view class="login-container">
    <!-- 蓝色头部区域 -->
    <view class="header-section">
      <view class="logo-circle"></view>
    </view>
    
    <!-- 主要内容区域 -->
    <view class="content-section">
      <view class="title">案源网</view>
      <view class="subtitle">连接律师与案件的专业平台</view>
      
      <!-- 微信登录按钮 -->
      <button class="wechat-login-btn" open-type="getUserInfo" @getuserinfo="onWechatLogin">
        <view class="wechat-icon">💬</view>
        <text class="wechat-text">微信快捷登录</text>
      </button>
      
      <!-- 用户协议 -->
      <view class="agreement-section">
        <text class="agreement-text">登录即表示同意</text>
        <view class="agreement-links">
          <text class="link" @click="showUserAgreement">用户协议</text>
          <text class="separator">和</text>
          <text class="link" @click="showPrivacyPolicy">隐私政策</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { setCurrentUser } from '../../src/services/userService.js'

export default {
  data() {
    return {
      userInfo: null
    }
  },
  methods: {
    onWechatLogin(e) {
      console.log('微信登录', e)
      if (e.detail.userInfo) {
        this.userInfo = e.detail.userInfo
        // 模拟获取用户手机号（实际项目中需要通过微信API获取）
        const mockPhone = '13800000001'
        setCurrentUser({ 
          phone: mockPhone,
          userInfo: e.detail.userInfo
        })
        uni.showToast({ title: '登录成功', icon: 'success' })
        setTimeout(() => {
          // 检查是否需要完善个人信息
          this.checkProfileComplete()
        }, 500)
      } else {
        uni.showToast({ title: '登录失败', icon: 'none' })
      }
    },
    checkProfileComplete() {
      const user = uni.getStorageSync('currentUser')
      if (!user.name || !user.organization) {
        // 跳转到完善个人信息页面
        uni.reLaunch({ url: '/pages/profile/setup' })
      } else {
        // 跳转到案件列表页面
        uni.reLaunch({ url: '/pages/cases/list' })
      }
    },
    showUserAgreement() {
      uni.showModal({
        title: '用户协议',
        content: '这里是用户协议的内容...',
        showCancel: false
      })
    },
    showPrivacyPolicy() {
      uni.showModal({
        title: '隐私政策',
        content: '这里是隐私政策的内容...',
        showCancel: false
      })
    }
  }
}
</script>

<style>
.login-container {
  min-height: 100vh;
  background: #f7f8fa;
  display: flex;
  flex-direction: column;
}

/* 蓝色头部区域 */
.header-section {
  height: 400rpx;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  position: relative;
  border-bottom-left-radius: 60rpx;
  border-bottom-right-radius: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-circle {
  width: 120rpx;
  height: 120rpx;
  background: #ffffff;
  border-radius: 50%;
  position: absolute;
  bottom: -60rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
}

/* 主要内容区域 */
.content-section {
  flex: 1;
  padding: 100rpx 60rpx 60rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title {
  font-size: 48rpx;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 16rpx;
  text-align: center;
}

.subtitle {
  font-size: 28rpx;
  color: #6b7280;
  margin-bottom: 80rpx;
  text-align: center;
  line-height: 1.5;
}

/* 微信登录按钮 */
.wechat-login-btn {
  width: 100%;
  height: 88rpx;
  background: #3b82f6;
  border-radius: 44rpx;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 60rpx;
  box-shadow: 0 4rpx 16rpx rgba(59, 130, 246, 0.3);
}

.wechat-icon {
  font-size: 32rpx;
  margin-right: 16rpx;
}

.wechat-text {
  color: #ffffff;
  font-size: 32rpx;
  font-weight: 600;
}

/* 用户协议区域 */
.agreement-section {
  position: absolute;
  bottom: 60rpx;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.agreement-text {
  font-size: 24rpx;
  color: #9ca3af;
  margin-bottom: 8rpx;
}

.agreement-links {
  display: flex;
  align-items: center;
}

.link {
  color: #3b82f6;
  font-size: 24rpx;
  text-decoration: underline;
}

.separator {
  color: #9ca3af;
  font-size: 24rpx;
  margin: 0 8rpx;
}
</style>
